<?php

/*
 *
 */

class Model_Mediate_PaybackMoneyLog extends Model_BaseModel
{
    use Lib_BaseTraits;
    /**
     * 缓存前缀
     *
     * @var unknown
     */
    private static $tag = 'Model_Mediate_PaybackMoneyLog';
    /**
     * Undocumented variable
     *
     * @var string
     */
    private $table = "payback_money_log";

    public function __construct()
    {
        // 选择连接的数据库
        parent::_init('mediation');
    }

    /**添加
     * @param $insertdata
     * @return mixed
     */
    public function insert($insertdata)
    {
        $data = array();
        $sql = 'INSERT INTO `payback_money_log`(';
        $sql .= '`' . implode('`,`', array_keys($insertdata)) . '`';
        $sql .= ')VALUES(:' . implode(',:', array_keys($insertdata)) . ')';
        foreach ($insertdata as $key => $value) {
            $data[':' . $key] = $value;
        }

        $res = $this->dao->conn(false)->noCache()->preparedSql($sql, $data)->affectedCount();
        $this->dao->clearTag(self::$tag);
        return $res;
    }

    /**
     * 获取还款记录
     */
    public function getPayBackLogs($case_id, $pay_time)
    {
        if (!$case_id) {
            return array();
        }
        $sql = "SELECT * FROM {$this->table} WHERE case_id = :case_id AND pay_time > :pay_time";
        $data = array(
            ':case_id' => $case_id,
            ':pay_time' => $pay_time,
        );
        return $this->dao->conn()->noCache()->preparedSql($sql, $data)->fetchAll();
    }

    /**
     * 获取还款记录
     */
    public function getPayBackLogsById($case_id)
    {
        if (!$case_id) {
            return array();
        }
        $sql = "SELECT * FROM {$this->table} WHERE case_id = :case_id ORDER BY pay_time";
        $data = array(
            ':case_id' => $case_id,
        );
        return $this->dao->conn()->noCache()->preparedSql($sql, $data)->fetchAll();
    }

}
